<template>
	<view class="community">
		<view class="head_bg" style="position: relative;"></view>
		<view class="big_box" style="margin-top:-160rpx;">
			<view class="count_tab">
				<view :class="{count_tab_inner1: istrue == true,is_active: tabIndex == 1}" @tap="tabSelect" :data-id="1" style="margin-left: 67rpx;">全部</view>
				<view :class="{count_tab_inner1: istrue == true,is_active: tabIndex == 2}" @tap="tabSelect" :data-id="2" >已完成</view>
				<view :class="{count_tab_inner1: istrue == true,is_active: tabIndex == 3}" @tap="tabSelect" :data-id="3">充电异常</view>
				<view :class="{count_tab_inner1: istrue == true,is_active: tabIndex == 4}" @tap="tabSelect" :data-id="4" style="margin-right: 60rpx;">充电失败</view>
			</view>
			<view>
				<view class="equ_list" v-for="(info,index) in list" :key="index" @tap="toOrderDetail">
					<view class="ele_title" style="padding-top:20rpx;">
						<view class="ele_title_left">
							<view class="ele_title_inner">{{info.residential_quarters_name}}</view>
							<view class="ele_address">
								<image class="ele_address_img" src="../../../../common/img/dizhi_hui.png" mode=""></image>
								<text>{{info.residential_quarters_address}}</text>
							</view>
						</view>
						<view v-if="info.task_state=='1'" style="color: grey;" class="falt_status">待充电</view>
						<!-- <view v-if="info.task_state=='充电中'" style="color: green;" class="falt_status">{{info.task_state}}</view> -->
						<view v-if="info.task_state=='4'" style="color: red;" class="falt_status">充电失败</view>
						<view v-if="info.task_state=='3'" style="color: #EF8257;" class="falt_status">异常结束</view>
						<view v-if="info.task_state=='2'" style="color: #52A8FF;" class="falt_status">已完成</view>
						<!-- <view v-if="info.task_state==1" style="color: #00BC43;" class="falt_status">充电中</view>
						<view v-if="info.task_state==2" style="color: #00BC43;" class="falt_status">已结束</view>
						<view v-if="info.task_state==3" class="falt_status"></view>
						<view v-if="info.task_state==4" class="falt_status">充电失败</view> -->
					</view>
					<view class="equ_list_inner">
						<view v-if="tabIndex!=4" class="equ_list_inner_text">充电时长：{{info.charging_minutes}}</view> 
						<view class="equ_list_inner_text">终端编号：{{info.equipment_number}} 
						</view>
						<view v-if="info.task_state!=3 && info.task_state!=1" class="equ_list_inner_text">起止时间：{{info.begin_time}} 至 {{info.end_time}}</view>
						<view v-else class="equ_list_inner_text">起止时间：{{info.begin_time}}</view>
					</view>
					<view class="count_bottom padding-top-xs padding-bottom-xs" v-if="info.task_state==3">
						<view style="text-align: left;padding-right: 20rpx;" class="text-red">{{info.abnormal_causes}}
							<text style="float: right;"> 
							<text v-if="info.consumption_pattern==2" 
							style="color: #75BFF9;padding-right: 20rpx;">套餐</text>
							<text class="text-black">结算：</text><text style="color: #EF8257;">{{info.consumption_amount}}</text>
							</text>
						</view>
					</view>
					<view class="count_bottom padding-top-xs padding-bottom-xs" v-else>
						<view style="text-align:right;padding-right: 20rpx;">
							<text v-if="info.consumption_pattern==2" 
							style="color: #75BFF9;padding-right: 20rpx;">套餐</text>
							<text class="text-black">结算：</text><text style="color: #EF8257;">{{info.consumption_amount}}</text>
						</view>
					</view>
					<!-- <view class="count_bottom padding-top-xs padding-bottom-xs" >
						
					</view> -->
				</view>
				<view style="height:100rpx;"></view>
				<view v-if="list.length==0" class="margin-top-lg text-center">
					<image src='../../../../common/img/no_data.png' style="width:275rpx;height:312rpx;"></image>
				</view>
				<view v-if="list.length>0" class="text-black text-df text-center bg-white padding-sm padding-left-lg be-gray">
					{{loadingTxt}} 共({{list.length}}条记录)
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	let page=1,timer=null
	export default {
		data() {
			return {
				loadingTxt:'加载更多',
				tabIndex: 1,
				istrue:true,
				list:[],//全部订单
			}
		},
		onShow() {
			page=1;
			this.getalllist();
		},
		methods: {
			tabSelect(e) {
				page=1;
				this.tabIndex = e.currentTarget.dataset.id;
				this.list=[];
				this.loadingTxt='加载更多',
				this.getalllist();
			},
			getalllist(){
				let that=this;
				let type;
				if(this.tabIndex==1){
					type="0";
				}else if(this.tabIndex==2){
					type="1";
				}else if(this.tabIndex==3){
					type="2";
				}else{
					type="3";
				}
				that.http.tokenreq({
					url: "user/v1/order",
					data:{
						'pageindex':page,
						"type":type
					}
				}).then((res) => {
					let e=res.data;
					// console.log(e)
					if(e.code==0 && e.success){
						that.list=e.rows;
						page++
					}
				})
			},
			getmorelist(){
				this.loadingTxt='加载中'
				let that=this;
				let type;
				if(this.tabIndex==1){
					type="0";
				}else if(this.tabIndex==2){
					type="1";
				}else if(this.tabIndex==3){
					type="2";
				}else{
					type="3";
				}
				that.http.tokenreq({
					url: "user/v1/order",
					data:{
						'pageindex':page,
						"type":type
					}
				}).then((res) => {
					uni.hideLoading();
					let e=res.data;
					if(e.code==0 && e.success){
						if(e.rows.length==0){
							that.loadingTxt="已经加载全部";
							return;
						}
						that.list=that.list.concat(e.rows);
						page++;
					}
				})
			},
			onReachBottom() {
				//阻止重复加载
				if(timer !== null){
					clearTimeout(timer)
				}
				timer=setTimeout(()=>this.getmorelist(),500)
			},
			toOrderDetail(){
				uni.navigateTo({
					url: '../orderDetail/orderDetail'
				})
			}
		}
	}
</script>
<style>
	page{
		background-color: #FFFFFF;
	}
	.foot{
		position:fixed;
		left:0;
		bottom: 0;
		width: 100%;
	}
	.equ_list_inner{
		margin: 0;
		padding: 10rpx 30rpx;
	}
	.equ_list{
		padding-bottom: 10rpx;
	}
	.ele_title{
		padding-bottom: 20rpx;
	}
	.operating_box_inner{
		background-color: #F5FBFF;
		border-radius: 20rpx;
		padding-bottom: 20rpx;
	}
	.money_details_text{
		color: #000000;
	}
	.money_details_inner1{
		margin-top: 20rpx;
	}
	.money_details_number{
		color: #000000;
	}
</style>
